Written by: Prograph International (Tim Snyder, Lynn McKaig)
Contents: Scrollbar Example.pgs
Scrollbar Example.ReadMe
ScrollProc.XPRIM
ScrollProc.lib
Needs Prograph Extensions:
Math Primitives
More Primitives
Primitives
ScrollProc.XPRIM
Needs Libraries to Compile:
ScrollProc.lib
SCLibrary 2.6
Library 2.6
Description
------------
The Scroll Bar class illustrates how easy it is to extend Prograph's supplied System Classes by creating a subclass and overshadowing some methods. The result is a standalone scroll bar window item that you can place in your windows and manipulate just like other window items.
In this particular case, the Open method calls the Mac Toolbox call NewControl and saves the control record in an attribute; the Close method deletes the control record; the Mouse Down method calls TestControl and TrackControl, and then calls the user's click method if necessary; the Update method calls Draw1Control; and the Hilite method calls HiliteControl. The getting and setting of the various attributes is overshadowed to call appropriate routines in the Control Manager; therefore, you should access the values of these attributes via the overshaowing methods, never directly. For example, when setting the "max" attribute with a set attribute operation, name the operation "/max" rather than "max".
Controls on the Macintosh are required to have an "action procedure" whose address is supplied to the TrackControl call. Since Prograph code cannot be called directly by the toolbox, the action procedure was written in C and a primitive (scroll-proc) is provided to return its address. This primitive resides in the ScrollProc.XPRIM file for the Interpreter and the ScrollProc.lib file for the compiler. The action procedure must have access to attributes in the Scroll Bar instance, so the primitive object-to-address is used so that the handle to the instance can be placed in the contrlRfCon field of the ControlRecord.
The example application in this file simply uses three scroll bars as gauges for setting red, green and blue color components, with the resulting color being drawn in a square patch.
How To Use This In Your Program
-------------------------------
Selectively load the Scroll Bar class. To add scrollbar items to your window, open the window from the Application Builder in the usual way. Create a Window Item, double-click on the item and choose "Scroll Bar" from the list of window items presented in the dialog. Enter a name and a click method for your scrollbar. What will now appear in your window (while in the Window Editor) will be a rectangle, depicting the shape of the scrollbar. When you run your application this item will be a functional scrollbar; not just a rectangle. Set the min, max, value, line pixels and page pixels attributes to values you want them to have initially, by shift-option-cmd-clicking on the item in the window editor to bring up a value window for the instance.